package org.mark.storage.controller;

import org.mark.common.response.Result;
import org.mark.common.entity.FreshFood;
import org.mark.storage.service.FreshFoodService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 生鲜信息
 */
@RestController
@RequestMapping("/freshFood")
@CrossOrigin
public class FreshFoodController {

    @Resource
    private FreshFoodService freshFoodService;

    @GetMapping("/page")
    public Result page(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(required = false) String name) {
        return freshFoodService.page(pageNum, pageSize, name);
    }

    @PostMapping("/save")
    public Result save(@RequestBody FreshFood freshFood) {
        return freshFoodService.save(freshFood);
    }

    @PostMapping("/update")
    public Result update(@RequestBody FreshFood freshFood) {
        return freshFoodService.update(freshFood);
    }

    // 将 DeleteMapping 改为 PostMapping
    @PostMapping("/remove")
    public Result remove(@RequestBody Map<String, Integer> params) {
        return freshFoodService.remove(params.get("id"));
    }

    @GetMapping("/storage/list")
    public Result storageList() {
        return freshFoodService.storageList();
    }

    @PostMapping("/list")
    @ResponseBody
    public Result list() {
        return freshFoodService.list();
    }

    @GetMapping("/{id}")
    public FreshFood getById(@PathVariable("id") Integer id) {
        return freshFoodService.getById(id);
    }

}